home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programmer's Power Pack / Delphi Volume 1.iso / s_to_z / t_rex10 / trexdmo2.dpr < prev    next >
Text File  |  1996-09-15  |  3KB  |  82 lines

  1. program Trexdmo2;
  2.  
  3. {
  4. $Log:   W:/users/prodigy/prodig~1/archive/trex/trexdmo2.dpv  $
  5.    
  6.       Rev 1.1   07 Apr 1996 18:30:22   PaulK
  7.    Work in progress on demos
  8. }
  9.  
  10. uses
  11.   Forms,
  12.   Trexdm02 in 'TREXDM02.PAS' {Form1};
  13.  
  14. {$R *.RES}
  15. {$R TREXDEMO.RES}
  16.  
  17. {This demo program scans a Pascal program and reports on the
  18.  number of lines that consist entirely of comments. For example,
  19.  this comment would count as 5 comment lines. But the comment in
  20.  the Uses clause has program text outside the comment on the same
  21.  line and so would not count.}
  22.  
  23. {The program uses 5 regular expressions to determine
  24.  commenthood. Every line is tested against each one in sequence;
  25.  but a match on one causes the other tests to be skipped. The
  26.  program causes this behaviour by calling SeekEoln after a match.
  27.  T-Rex's normal behaviour is to match every MatchPattern.}
  28.  
  29. {Here is a walkthrough of the regular expressions you will find
  30.  in the MatchPattern property. There's no room for comments there.}
  31.  
  32. (* 1: ^ *({[^}]*} * )+$
  33.    Starting at beginning of line "^", there may be 0 or more
  34.    spaces " *" and then a brace "{" [ignore parenthesis for the
  35.    moment; discussed below]. This can be followed by any number
  36.    of nonbrace characters inside the comment "[^}]*" but a
  37.    single closing brace "}" ends the comment. After that, there
  38.    can be zero or more spaces " *". This pattern can be repeated
  39.    more than once (....)+ before the end of line
  40.    "$" is reached. In other words, the comment starts and ends
  41.    on a single line (or several of them all start and end on
  42.    the same line), and there is nothing but spaces before and
  43.    after it/them on that line. [There is a spurious space before
  44.    ")+$" in the expression as shown here to avoid closing this
  45.    Pascal comment prematurely.]                                 *)
  46.  
  47. (* 2: ^ *{[^}]*$
  48.    Starting at beginning of line "^", there may be 0 or more
  49.    spaces " *" and then a brace "{". This can be followed by
  50.    any number of nonbrace characters inside the comment
  51.    "[^}]*". The end of line "$" is reached before
  52.    a closing brace is found. In other words, the comment starts
  53.    on this line, but does not end on it, and there is nothing but
  54.    spaces before the comment.                                   *)
  55.  
  56. (* 3: {[^}]*$
  57.    A comment begins "{" on this line, but does not end. There must
  58.    be some non-comment stuff before the left brace, else pattern
  59.    2 would have matched. So this is the start of a multiline
  60.    comment, but does not itself add to the comment linecount,
  61.    because this line does not consist solely of comments.       *)
  62.  
  63. (* 4: } *$
  64.    A comment ends "}" on this line, and there are only 0 or more
  65.    spaces " *" before the end of line "$" is reached. The comment
  66.    did not begin on this line (else 1-3 would have matched).    *)
  67.  
  68. (* 5: }
  69.    A comment ends "}" on this line, but 4 did not match so there
  70.    must have been some code after the comment.                  *)
  71.  
  72. {This is a demo program, not a serious application. The following
  73.  are not handled:
  74.  1. Comments of the form (* *).
  75.  2. Comments that contain left braces.                           }
  76.  
  77.  
  78. begin
  79.   Application.CreateForm(TForm1, Form1);
  80.   Application.Run;
  81. end.
  82.